<!--
 * @Descripttion: unTitle
 * @Author: yizheng.yuan
 * @Date: 2021-11-16 10:20:44
 * @LastEditors: yizheng.yuan
 * @LastEditTime: 2021-11-16 13:53:43
-->
<template>
  <div class="home">
    <div class="header">
      <span>某某管理系统</span>
      <el-dropdown @command="handleCommand">
        <span class="el-dropdown-link">
          {{username}}<i class="el-icon-arrow-down el-icon--right"></i>
        </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item command="userCenter">个人中心</el-dropdown-item>
          <el-dropdown-item command="logout">退出系统</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
    <div class="container">
      <div class="sider">
        
        <el-menu
          :router="true"
          default-active="2"
          class="el-menu-vertical-demo">
          <el-submenu index="1">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>导航一</span>
            </template>
            <el-menu-item index="/user">用户管理</el-menu-item>
            <el-menu-item index="/right">权限管理</el-menu-item>
          </el-submenu>
        </el-menu>
        
      </div>
      <div class="main">
        <!-- 切换的页面将在这里展示 -->
        <router-view></router-view>
      </div>
    </div>
  </div>
</template>

<script>
// @ is an alias to /src
// 引入vuex
import {mapState} from 'vuex';
export default {
  name: 'Home',
  components: {
  },
  computed:{
    ...mapState(['username'])
  },
  methods:{
    handleCommand(command) {
      // this.$message('click on item ' + command);
      if(command === 'logout'){
        // 保存username到localStorage
        window.localStorage.setItem('username', '');
        // 将用户名保存到vuex
        this.$store.commit('updateUsername', '')
        // 跳转登录
        this.$router.push('/login')
      }
    }
  }
}
</script>

<style scoped>
.home{
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.header{
  height: 60px;
  line-height: 60px;
  padding: 0 10px;
  font-size: 18px;
  background-color: #69f;
  color: #eee;
  text-align: left;
  display: flex;
  justify-content: space-between;
}
.el-dropdown-link{
  color: #eee;
}
.container{
  flex: 1;
  display: flex;
  margin-top: 5px;
}
.sider{
  height: 100%;
  width: 250px;
  background-color: #ccc;
}
.main{
  flex: 1;
  margin-left: 5px;
  
  border: 1px solid #ddd;
  background-color: #eee;
}
</style>
